package com.galeno.udfs;

import com.alibaba.fastjson.JSON;
import com.galeno.pojo.LogBean;
import lombok.extern.log4j.Log4j;
import org.apache.flink.streaming.api.functions.ProcessFunction;
import org.apache.flink.util.Collector;

/**
 * @author galeno
 * @Title:
 * @Description:
 * @date 2021/11/119:20
 */
@Log4j
public class JSON2LogBean extends ProcessFunction<String, LogBean> {
    @Override
    public void processElement(String json, Context ctx, Collector<LogBean> out) throws Exception {

        try {
            LogBean logBean = JSON.parseObject(json, LogBean.class);
            out.collect(logBean);
        } catch (Exception e) {
            e.printStackTrace();
            //错误的json解析用log接收
            log.error(json);

        }


    }
}
